local skel = fk.CreateSkill {
  name = "emo__jueyi",
}

Fk:loadTranslationTable{
  ["emo__jueyi"] = "决意",
  [":emo__jueyi"] = "出牌阶段限一次，你可以失去体力至1点或弃置所有手牌，若如此做，你摸X张牌且本回合手牌上限+X，且本回合结束时，若这些牌均不在你手牌中，你回复一点体力（X为失去体力数或弃牌数）。",

  ["@@emo__jueyi-turn-inhand"] = "决意",
  ["#emo__jueyi_delay"] = "决意",
  ["#emo__jueyi-prompt"] = "决意：你可失去体力至1点或弃置所有手牌，摸失去体力数的两倍或弃牌数张牌",
  ["#emo__jueyi-loseHp"] = "失去体力至1点",
  ["#emo__jueyi-discard"] = "弃置所有手牌",
}

skel:addEffect("active", {
  anim_type = "offensive",
  card_num = 0,
  target_num = 0,
  card_filter = Util.FalseFunc,
  interaction = function (self, player)
    local all_choices = {"#emo__jueyi-loseHp", "#emo__jueyi-discard"}
    local choices = {}
    if player.hp > 1 then
      table.insert(choices, all_choices[1])
    end
    if not player:isKongcheng() then
      table.insert(choices, all_choices[2])
    end
    return UI.ComboBox { choices = choices, all_choices = all_choices }
  end,
  prompt = "#emo__jueyi-prompt",
  times = function (self, player)
    return 1 - player:usedSkillTimes(skel.name, Player.HistoryPhase)
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryPhase) == 0 and (player.hp > 1 or not player:isKongcheng())
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local choice = self.interaction.data
    local num = 0
    if choice == "#emo__jueyi-loseHp" then
      num = player.hp - 1
      room:loseHp(player, num, skel.name)
    else
      num = player:getHandcardNum()
      player:throwAllCards("h")
    end
    if player.dead then return end
    room:setPlayerMark(player, "emo__jueyi-turn", 1)
    room:addPlayerMark(player, MarkEnum.AddMaxCardsInTurn, num)
    player:drawCards(num, skel.name, "top", "@@emo__jueyi-turn-inhand")
  end,
})

skel:addEffect(fk.TurnEnd, {
  is_delay_effect = true,
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("emo__jueyi-turn") > 0 and player:isWounded()
    and not table.find(player:getCardIds("h"), function (id)
      return Fk:getCardById(id):getMark("@@emo__jueyi-turn-inhand") ~= 0
    end)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:recover { num = 1, skillName = skel.name, who = player, recoverBy = player}
  end,
})


return skel
